home *** CD-ROM | disk | FTP | other *** search
- using System;
- using System.IO;
- using System.Text.RegularExpressions;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Xml;
-
- namespace gbweb
- {
- /// <summary>
- /// Summary description for Search.
- /// </summary>
- public partial class PhotoDirectory : Page
- {
-
- private Regex filter = new Regex(Global.Settings.photoFiles, RegexOptions.Compiled | RegexOptions.IgnoreCase);
-
- protected void Page_Load(object sender, EventArgs e)
- {
- //If first time page is being displayed
- if (!IsPostBack)
- {
- //Default the directorylist variable
- string directorylist = "Photo~|";
- //Get the photo libraries from the GBPVR Config File
- XmlNode node = Global.Config.SelectSingleNode("/settings/PhotoLibraryDirectory");
- //Create arrays to hold the libraries and directories within the libraries
- string[] directories = new string[500];
- string[] libraries = new string[500];
- //If a Photo Library was found in the config
- if (node != null)
- {
- //Get the list of libraries and directories from the node
- directorylist = node.InnerText;
- //Split eaach record from the node into a Libarary and Directory
- string[] directorymappings = directorylist.Split('|');
- int i = 0;
- //Sort the array of libraries and directories
- Array.Sort(directorymappings);
- //Loop through the array laoding the Libraries and Directories to their own array
- foreach (string directorymapping in directorymappings)
- {
- //If there is something in the library directory record load each piece to the array
- if (directorymapping != "")
- {
- //Split the library directory record into the two seperate pieces
- string[] mapping = directorymapping.Split('~');
- //If there is a library found load the appropriate array
- if ((directorymapping.Length > 0) && (mapping.Length > 1))
- {
- libraries[i] = mapping[0];
- directories[i] = mapping[1];
- }
- //Increment the index used for loading the libaray and directory array
- i++;
- }
- }
-
- //Resize the arrays to free up unused space
- Array.Resize(ref libraries, i);
- Array.Resize(ref directories, i);
- //Loop through each entry in the directory array to build the list of libraries and directories
- //that is loaded into the tree
-
- for (i = 0; i < directories.Length;i++ )
- {
- //Create a new set of nodes for holding all the info
- TreeNodeCollection oNodes = new TreeNodeCollection();
- //Call the method to build and load the directories for loading to the treeview control
- BuildTree(directories[i], oNodes);
- // Create a node for the library name
- TreeNode oNode = new TreeNode();
- //Set the node name to the name of the library
- oNode.Text = libraries[i];
- //Set the action to occur when the library node is clicked on
- oNode.SelectAction = TreeNodeSelectAction.Expand;
- //Loop through the nodes that contain all the directy and file information and load them into
- //the library node....this makes them show up under the libaray
- foreach (TreeNode tnode in oNodes)
- {
- oNode.ChildNodes.Add(tnode);
- }
- //Set the library node to be collapsed
- oNode.Expanded = false;
- //Add the library node (which now contains all the directoy and file nodes) to the treeview control
- TreeView1.Nodes.Add(oNode);
- }
- //Set the images used by the treeview control to be like the windows file explorer icons
- TreeView1.ImageSet = TreeViewImageSet.XPFileExplorer;
- }
- //Shrink the arrays down to 0
- Array.Resize(ref directories, 0);
- Array.Resize(ref libraries, 0);
- }
-
- }
-
- #region Web Form Designer generated code
- override protected void OnInit(EventArgs e)
- {
- //
- // CODEGEN: This call is required by the ASP.NET Web Form Designer.
- //
- InitializeComponent();
- base.OnInit(e);
- }
-
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
-
- }
- #endregion
-
-
-
- // Recursively loops through folder structure and
- // loads all folders and files into TreeView.
- // Each iteration gets files and folders
- // immediately within current folder.
-
- private void BuildTree(string sPath, TreeNodeCollection oNodes)
- {
- try
- {
- // Load all folders in current path into array
- string[] aFolders = Directory.GetDirectories(sPath);
- Array.Sort(aFolders);
- // Loop through all folders in current path,
- // create nodes for them and load them into
- // TreeView
- foreach (string sTempFolder in aFolders)
- {
- // Strip path out and retrieve folder name
- // only
- string sFolder = sTempFolder.Substring(sPath.Length + 1);
-
- //Create node for folder and add it to
- oNodes.Add(CreateFolderNode(sFolder));
- }
-
- // Load all JPGs in current path into array
- string[] aFiles = Directory.GetFiles(sPath, "*.jpg");
- Array.Sort(aFiles);
- // Loop through files in current path, create
- // nodes for them and load them into TreeView
- foreach (string sFile in aFiles)
- {
- // Create node for file; add it to
- // TreeView. Pass in path with file name of
- // file (text for file node)
- if (filter.IsMatch(sFile))
- {
- oNodes.Add(CreateFileNode(sFile, sFile.Substring(sPath.Length + 1)));
- }
- }
-
- // Recursively call GetFolders method for
- // subfolder
- for (int i = 0; i < oNodes.Count; i++)
- {
- // If the node is a folder ...
- if (!filter.IsMatch(oNodes[i].Text.ToLower()))
- {
- // Recursively call GetFolders method for
- // subfolder
- //BuildTree(aFolders[i] + "\\", oNodes[i].ChildNodes);
- BuildTree(aFolders[i], oNodes[i].ChildNodes);
- }
- }
- }
- catch (Exception e)
- {
- return;
- }
- }
-
-
- // Create file TreeNode from specified path
- private static TreeNode CreateFileNode(string sPath, string sText)
- {
- // Create a node
- TreeNode oNode = new TreeNode();
-
- // Set the display text for the node
- oNode.Text = sText;
- //Set the url of the node so that when clicked it activates the photo.aspx page and passes in the location of the photo.
- //The path of the photo is serialized so that it can be passed around and is not readable by a human.
- //The whole query string is set to utilze the download.ashx page to process the image.
- oNode.NavigateUrl = "Photo.aspx?pic=" + Download.GetDownloadUrl(false, true, Download.InternalFiles.Photo, PublicDownload.Serialize(sPath));
-
- // Point target for hyperlink to iframe
- oNode.Target = "ifImages";
-
- // Return the file node
- return oNode;
- }
-
- // Create a folder TreeNode from the specified path
- private static TreeNode CreateFolderNode(string sText)
- {
- // Create a node
- TreeNode oNode = new TreeNode();
-
- // Set the type to be folder
- //oNode.Type = "folder";
-
- // Set the display text for the node
- oNode.Text = sText;
- oNode.Expanded = false;
- oNode.SelectAction = TreeNodeSelectAction.Expand;
-
- // Return the folder node
- return oNode;
- }
- }
- }
-